package com.shanjupay.merchant.convert;



import com.shanjupay.merchant.api.dto.MerchantDTO;
import com.shanjupay.merchant.entity.Merchant;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;


//DTO和Entity进行互相转化
@Mapper //该注解的作用让MerchantCovert中merchantDTO和merchant进行互相转化
public interface MerchantCovert {
    //使用MerchantCovert调用getMapper方法进行获取接口mapper转换接
    MerchantCovert INSTANCE = Mappers.getMapper(MerchantCovert.class);
    //merchant中Entity转DTO
    MerchantDTO  entityToDto(Merchant merchant);
    //merchant中 dto转entity
    Merchant dtoToEntity(MerchantDTO merchantDTO);
    //List<Dto>转成List<Entity>
    List<MerchantDTO>     listentity2dto  (List<Merchant> merchants);

    public static void main(String[] args) {
        //测试entity转换dto
        //1创建entity实体对象
        Merchant merchant = new Merchant();
        merchant.setMobile("1234567");
        merchant.setAuditStatus("1");
        MerchantDTO merchantDTO = MerchantCovert.INSTANCE.entityToDto(merchant);
        System.out.println("merchantDTO = " + merchantDTO);
        //2测试DTO转换entity
        merchantDTO.setUsername("HMK");
        merchant = MerchantCovert.INSTANCE.dtoToEntity(merchantDTO);
        System.out.println("merchant = " + merchant);
        //List<Entity> 转换成List<DTO>
        //创建list<Entity>
        ArrayList<Merchant> merchants = new ArrayList<>();
        //list<Entity>转化成List<DTO>
        merchant.setId(13L);
        merchants.add(merchant);
        List<MerchantDTO> merchantDTOS = MerchantCovert.INSTANCE.listentity2dto(merchants);
        for (MerchantDTO merchantDTO1 : merchantDTOS) {
            System.out.println(merchantDTO1);
        }

    }
}
